package com.ayz.gateway.sdk.gatawayService.notify.event;



import com.ayz.gateway.common.notify.ApplicationEvent;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName AllocationApiDataChangeEvent
 * @Description TODO: 网关服务分配的API信息变更事件
 * @Author 快乐的星球
 * @Date 2023/5/31 21:16
 * @Version 1.0
 **/
@Getter
@Setter
public class AllocationApiDataChangeEvent extends ApplicationEvent {

    public AllocationApiDataChangeEvent(AllocationApiDataChangeInfo allocationApiDataChangeInfo) {
        super(allocationApiDataChangeInfo);
    }

    @Getter
    @Setter
    @AllArgsConstructor
    @NoArgsConstructor
    public static class ApiInfo{
        /**
         * 应用程序的名称
         */
        private String applicationName;
        /**
         * 接口的全类路径名称
         */
        private String interfaceName;
        /**
         * 注册中心的地址
         */
        private String registryAddress;
        /**
         * 当前API接口是同步还是异步
         * TODO: 现在还不支持方法级别的同步和异步,默认是接口级别设置
         */
        private boolean isAsync;
        /**
         * 调用的超时时间单位ms
         */
        private long timeout;
    }
    @Getter
    @Setter
    @AllArgsConstructor
    @NoArgsConstructor
    public static class MethodInfo{
        /**
         * 应用程序名称
         */
        private String applicationName;
        /**
         * 接口的名称
         */
        private String interfaceName;
        /**
         * 方法的名称
         */
        private String methodName;
        /**
         * 映射的Http接口的全类路径名
         */
        private String httpUri;
        /**
         * 是否是同步调用
         */
        private boolean isSync;

        /**
         * 参数的类型名称
         */
        private String parameterTypeName;
        /**
         * 是否鉴权
         */
        private boolean isAuth;
    }

    @Getter
    @Setter
    public static class AllocationApiDataChangeInfo{
        /**
         * 存储新增的API接口集合信息
         */
        private List<ApiInfo> addApiInfoList;
        /**
         * 存储删除的API接口集合信息
         */
        private List<ApiInfo> deleteApiInfoList;
        /**
         * 存储新增的方法信息集合
         */
        private List<MethodInfo> addMethodInfoList;
        /**
         * 存储删除的方法信息集合
         */
        private List<MethodInfo> deleteMethodInfoList;

        public AllocationApiDataChangeInfo(List<ApiInfo> addApiInfoList, List<ApiInfo> deleteApiInfoList, List<MethodInfo> addMethodInfoList, List<MethodInfo> deleteMethodInfoList) {
            this.addApiInfoList = addApiInfoList;
            this.deleteApiInfoList = deleteApiInfoList;
            this.addMethodInfoList = addMethodInfoList;
            this.deleteMethodInfoList = deleteMethodInfoList;
        }

        public AllocationApiDataChangeInfo() {
            this.addApiInfoList=new ArrayList<>();
            this.deleteApiInfoList=new ArrayList<>();
            this.addMethodInfoList=new ArrayList<>();
            this.deleteMethodInfoList=new ArrayList<>();
        }
    }
}
